/*
 * MouseHandler.java
 *
 * Created on July 30, 2007, 10:34 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.mar.bt.rd.server;

import java.awt.Robot;
import java.awt.event.InputEvent;
import java.util.Vector;

/**
 *
 * @author helio.rodrigues
 */
public class MouseHandler {
    
    private Robot robot;
    private int deviceWidth;
    private int deviceHeight;
    
    /**
     * Creates a new instance of MouseHandler
     *
     * @param robot
     */
    public MouseHandler(Robot robot) {
        this.robot = robot;
    }
    
    /**
     *
     * @param bytes
     */
    public void clickLeftButton(byte[] bytes) {
        Vector<String> params = IDesktopProtocol.parseParameters(bytes);
        int x = Integer.parseInt((String) params.elementAt(0));
        int y = Integer.parseInt((String) params.elementAt(1));
        
        if (x >= 0 && y >= 0) {
            robot.mouseMove(x, y);
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
        }
    }
    
    /**
     *
     * @param bytes
     */
    public void clickRightButton(byte[] bytes) {
        Vector<String> params = IDesktopProtocol.parseParameters(bytes);
        int x = Integer.parseInt((String) params.elementAt(0));
        int y = Integer.parseInt((String) params.elementAt(1));
        
        if (x >= 0 && y >= 0) {
            robot.mouseMove(x, y);
            robot.mousePress(InputEvent.BUTTON3_MASK);
            robot.mouseRelease(InputEvent.BUTTON3_MASK);
        }
    }
    
    /**
     *
     * @param bytes
     */
    public void pressLeftButton(byte[] bytes) {
        Vector<String> params = IDesktopProtocol.parseParameters(bytes);
        int x = Integer.parseInt((String) params.elementAt(0));
        int y = Integer.parseInt((String) params.elementAt(1));
        
        if (x >= 0 && y >= 0) {
            robot.mouseMove(x, y);
            robot.mousePress(InputEvent.BUTTON1_MASK);
        }
    }
    
    /**
     *
     * @param bytes
     */
    public void pressRightButton(byte[] bytes) {
        Vector<String> params = IDesktopProtocol.parseParameters(bytes);
        int x = Integer.parseInt((String) params.elementAt(0));
        int y = Integer.parseInt((String) params.elementAt(1));
        
        if (x >= 0 && y >= 0) {
            robot.mouseMove(x, y);
            robot.mousePress(InputEvent.BUTTON3_MASK);
        }
    }
    
    /**
     *
     * @param bytes
     */
    public void releaseLeftButton(byte[] bytes) {
        Vector<String> params = IDesktopProtocol.parseParameters(bytes);
        int x = Integer.parseInt((String) params.elementAt(0));
        int y = Integer.parseInt((String) params.elementAt(1));
        
        if (x >= 0 && y >= 0) {
            robot.mouseMove(x, y);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
        }
    }
    
    /**
     *
     * @param bytes
     */
    public void releaseRightButton(byte[] bytes) {
        Vector<String> params = IDesktopProtocol.parseParameters(bytes);
        int x = Integer.parseInt((String) params.elementAt(0));
        int y = Integer.parseInt((String) params.elementAt(1));
        
        if (x >= 0 && y >= 0) {
            robot.mouseMove(x, y);
            robot.mouseRelease(InputEvent.BUTTON3_MASK);
        }
    }
    
    /**
     * 
     * @param params 
     */
    public void moveMouse(byte[] bytes) {
        Vector<String> params = IDesktopProtocol.parseParameters(bytes);
        int x = Integer.parseInt((String) params.elementAt(0));
        int y = Integer.parseInt((String) params.elementAt(1));
        
        if (x >= 0 && y >= 0) {
            robot.mouseMove(x, y);
        }
    }
    
    /**
     *
     * @return
     */
    public int getDeviceWidth() {
        return deviceWidth;
    }
    
    /**
     *
     * @param deviceWidth
     */
    public void setDeviceWidth(int deviceWidth) {
        this.deviceWidth = deviceWidth;
    }
    
    /**
     *
     * @return
     */
    public int getDeviceHeight() {
        return deviceHeight;
    }
    
    /**
     *
     * @param deviceHeight
     */
    public void setDeviceHeight(int deviceHeight) {
        this.deviceHeight = deviceHeight;
    }

}
